<?php
/**
 * Created by PhpStorm.
 * User: liuyang
 * Date: 2018/9/29
 * Time: 14:14
 */

//加密
function bhmd5($str = '', $type = false, $time = 0, $key = ''){
    if($str == ''){
        return false;
    }
    $type = ($type) ? 'DECODE' : 'ENCODE';
    return model('tool')->bhmd5($str, $type, $key, $time);
}

function curl_post($url = '', $postdata = '', $options = array()){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    if(!empty($options)){
        curl_setopt_array($ch, $options);
    }
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

function curl_get($url = '', $options = array()){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    if(!empty($options)){
        curl_setopt_array($ch, $options);
    }
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}